package cur.nature.admin.dao;

import cur.nature.admin.common.config.DBAdminConfig;
import cur.nature.admin.model.po.admin_AddressPO;
import cur.nature.admin.model.vo.Admin_AddressVO;
import cur.nature.framework.core.util.StringUtil;
import cur.nature.framework.mvc.crud.CrudDao;
import cur.nature.tinyorm.core.bean.PageBean;

import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户信息 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2024-02-15 21:03:32
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class admin_AddressDao extends CrudDao<admin_AddressPO, Admin_AddressVO> {
    public admin_AddressDao(@Qualifier(DBAdminConfig.TEMPLATE) DefaultJdbcTemplate template) {
        super(admin_AddressPO.class, Admin_AddressVO.class, template);
    }

    public PageBean<Admin_AddressVO> list(Admin_AddressVO.list_Param param) throws Exception {
        StringBuilder condition = new StringBuilder(" 1=1 ");
//        if(StringUtil.isNotEmpty(param.getKeyword())){
//            condition.append(" and a.code like '"+param.getKeyword()+"%'");
//        }
        final String sql = StringUtil.format("select {0} from {1} where {2} ", cols(), tableName(),condition);
         PageBean<Admin_AddressVO> list = queryForPage(sql, param.buildPage(), Admin_AddressVO.class);
        return list;
    }

    public List<Admin_AddressVO> queryByCond(Admin_AddressVO.getDefaultAddress_Param param) throws Exception {
        // 过滤条件
        final StringBuilder cond = new StringBuilder();
        cond.append(" and user_id=" + param.getUserId()+" and type=1 ");
        // 查询出所有的资源
        List<Admin_AddressVO> list = queryByCond(cond.toString());
        return list;
    }

}

